package com.lfx.concurrent;

import java.util.LinkedList;
import java.util.Queue;

public class RequestQueue {

    private final Queue<Request> requestQueue=new LinkedList<>();

    public synchronized   Request getReques(){
        while (requestQueue.peek()==null){//队列为空，则进行阻塞
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //取出消息
        return requestQueue.remove();
    }


    /**
     * 放消息
     * @param request
     */
    public synchronized void put(Request request ){
        requestQueue.offer(request);
        notifyAll();
    }




}
